<%@ page language="java" import="java.util.*,com.ce.sys.login.model.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/sys/org/";  //应用的地址名
String orgId = "";
User user = User.getUser();
String orgTreeUrl="";
if(user!=null){
	orgId = user.getRootOrgId();
	
	if(user.isSuperUser()){
		orgId="";
		orgTreeUrl=path+"/util/util_getOrgTreeNodes.action?pid="+orgId;  //获取json格式的节点树;
	}else{
		orgTreeUrl=path+"/util/util_getOrgTreeNode.action?pid="+orgId+"&treeType=2";  //获取json格式的节点树;
	}
}

%>
<script type="text/javascript">

     $(function(){
		$('#orgManagerTree').tree({   
		    //checkbox: true,    
		    url:'<%=orgTreeUrl%>',  //获取json格式的节点树
            
          	//打开节点时的操作
		    onClick:function(node){
                 //将选中的机构id值放入人员的datagrid，然后重新载入 	               
	            var queryParams = $('#searchTable').datagrid("options").queryParams;  
	            queryParams['search.orgId']=node.id;//赋值查询参数值 
	            $('#searchTable').datagrid("options").pageNumber = 1;
			    $('#searchTable').datagrid('reload');
				
		    },
		    onExpand:function(node){
		    	var ns = $('#orgManagerTree').tree('getChildren',node.target);
		    	if(ns.length==1&&ns[0].id=='tmp_loading'){//加载子节点
		    		$.getJSON('<%=path%>/util/util_getOrgTreeNodes.action?pid='+node.id,function(data){
		    			$('#orgManagerTree').tree('remove',ns[0].target);
			    		if(data&&data.length>0){
		    				$('#orgManagerTree').tree('append',{parent:node.target,data:data[0].children});
			    		}
		    		});
		    	}
		    },
		    //加载数据失败的处理        
		    onLoadError: function () {    
		        $.messager.alert('消息提示','机构树加载失败，请稍后再试！','error'); 
		    }
                                 
		        });      
         }); 
         
 
</script>

<ul id="orgManagerTree"></ul>